/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.test.base;

import cn.hutool.core.util.ObjUtil;
import info.peigen.hotpot.common.core.enums.YesOrNo;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.core.result.ResultStatus;
import info.peigen.hotpot.common.service.base.test.ServiceTestContext;
import info.peigen.hotpot.common.service.base.test.ServiceTestInvoke;
import info.peigen.hotpot.common.service.base.test.mock.ServiceTestMockContext;
import info.peigen.hotpot.common.service.base.test.mock.ServiceTestMockContextThreadLocal;
import info.peigen.hotpot.manage.core.cache.ManageCache;
import info.peigen.hotpot.manage.core.enums.*;
import info.peigen.hotpot.manage.core.repository.entity.OrganizationEntity;
import info.peigen.hotpot.manage.core.repository.entity.PositionEntity;
import info.peigen.hotpot.manage.core.repository.entity.ResourceEntity;
import info.peigen.hotpot.manage.core.repository.entity.RoleEntity;
import info.peigen.hotpot.manage.core.service.*;
import info.peigen.hotpot.manage.core.service.order.*;
import info.peigen.hotpot.manage.core.service.result.*;
import info.peigen.hotpot.manage.core.service.result.info.*;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import org.junit.jupiter.api.Assertions;
import org.noear.solon.annotation.Inject;

/**
 * <b>(HotpotManageServiceTestBase)</b>
 * 服务测试用例基类
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-06-28
 */
@SuppressWarnings("UnusedReturnValue")
@FieldDefaults(level = AccessLevel.PROTECTED)
public class HotpotManageServiceTestBase extends HotpotManageRepositoryTestBase {
    @Inject
    ManageCache         manageCache;
    @Inject
    RoleService         roleService;
    @Inject
    RelationService     relationService;
    @Inject
    OrganizationService organizationService;
    @Inject
    UserService         userService;
    @Inject
    PositionService     positionService;
    @Inject
    ResourceService     resourceService;

    public String createRoleTest(int serial, String organizationId, String name, String code, RoleCategory category, Integer sort, String ext,
                                 ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                roleMapper.deleteByName(name);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                RoleCreateOrder order = RoleCreateOrder.builder()
                        .partnerId(PARTNER_ID)
                        .organizationId(organizationId)
                        .name(name)
                        .code(code)
                        .category(RoleCategory.getRandomEnum())
                        .sort(null)
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                RoleCreateResult result = roleService.create((RoleCreateOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                RoleCreateResult result = (RoleCreateResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((RoleInfo) serviceTestContext.getSingleResult().getInfo()).getRoleId();
    }

    public String editRoleTest(int serial, String organizationId, String name, String code, RoleCategory category, Integer sort, String ext,
                               ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                String roleId = createRoleTest(serial, organizationId, name, code, category, sort, ext, resultStatus, resultCode, detail);
                serviceTestContext.getExtend().put("key", roleId);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                String roleId = (String) serviceTestContext.getExtend().get("key");
                RoleEditOrder order = RoleEditOrder.builder()
                        .partnerId(PARTNER_ID)
                        .roleId(roleId)
                        .organizationId(organizationId)
                        .name(name)
                        .code(code)
                        .category(RoleCategory.getRandomEnum())
                        .sort(sort)
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                RoleEditResult result = roleService.edit((RoleEditOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                RoleEditResult result = (RoleEditResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((RoleInfo) serviceTestContext.getSingleResult().getInfo()).getRoleId();
    }

    public String createOrganizationTest(int serial, String parentId, String manageId, String name, String code, ManageOrgCategory category, Integer sort, String ext,
                                         ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                organizationMapper.deleteByName(name);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                OrganizationCreateOrder order = OrganizationCreateOrder.builder()
                        .partnerId(PARTNER_ID)
                        .parentId(parentId)
                        .manageId(manageId)
                        .name(name)
                        .code(code)
                        .category(ManageOrgCategory.getRandomEnum())
                        .sort(null)
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                OrganizationCreateResult result = organizationService.create((OrganizationCreateOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                OrganizationCreateResult result = (OrganizationCreateResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((OrganizationInfo) serviceTestContext.getSingleResult().getInfo()).getOrganizationId();
    }

    public String editOrganizationTest(int serial, String parentId, String manageId, String name, String code, ManageOrgCategory category, Integer sort, String ext,
                                       ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                String organizationId = createOrganizationTest(serial, parentId, manageId, name, code, category, sort, ext, resultStatus, resultCode, detail);
                serviceTestContext.getExtend().put("key", organizationId);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                String organizationId = (String) serviceTestContext.getExtend().get("key");
                OrganizationEditOrder order = OrganizationEditOrder.builder()
                        .partnerId(PARTNER_ID)
                        .organizationId(organizationId)
                        .parentId(parentId)
                        .manageId(manageId)
                        .name(name)
                        .code(code)
                        .category(ManageOrgCategory.getRandomEnum())
                        .sort(sort)
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                OrganizationEditResult result = organizationService.edit((OrganizationEditOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                OrganizationEditResult result = (OrganizationEditResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((OrganizationInfo) serviceTestContext.getSingleResult().getInfo()).getOrganizationId();
    }

    public String createPositionTest(int serial, String organizationId, String name, String code, PositionCategory category, Integer sort, String ext,
                                     ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                positionMapper.deleteByName(name);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                PositionCreateOrder order = PositionCreateOrder.builder()
                        .partnerId(PARTNER_ID)
                        .organizationId(organizationId)
                        .name(name)
                        .code(code)
                        .category(PositionCategory.getRandomEnum())
                        .sort(null)
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                PositionCreateResult result = positionService.create((PositionCreateOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                PositionCreateResult result = (PositionCreateResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((PositionInfo) serviceTestContext.getSingleResult().getInfo()).getPositionId();
    }

    public String editPositionTest(int serial, String organizationId, String name, String code, PositionCategory category, Integer sort, String ext,
                                   ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                String positionId = createPositionTest(serial, organizationId, name, code, category, sort, ext, resultStatus, resultCode, detail);
                serviceTestContext.getExtend().put("key", positionId);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                String positionId = (String) serviceTestContext.getExtend().get("key");
                PositionEditOrder order = PositionEditOrder.builder()
                        .partnerId(PARTNER_ID)
                        .positionId(positionId)
                        .organizationId(organizationId)
                        .name(name)
                        .code(code)
                        .category(PositionCategory.getRandomEnum())
                        .sort(sort)
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                PositionEditResult result = positionService.edit((PositionEditOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                PositionEditResult result = (PositionEditResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((PositionInfo) serviceTestContext.getSingleResult().getInfo()).getPositionId();
    }

    public String createRelationTest(int serial, String objectId, String targetId, RelationCategory category, String ext,
                                     ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                relationMapper.deleteByObjectId(objectId);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                RelationCreateOrder order = RelationCreateOrder.builder()
                        .partnerId(PARTNER_ID)
                        .objectId(objectId)
                        .targetId(targetId)
                        .category(RelationCategory.getRandomEnum())
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                RelationCreateResult result = relationService.create((RelationCreateOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                RelationCreateResult result = (RelationCreateResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((RelationInfo) serviceTestContext.getSingleResult().getInfo()).getRelationId();
    }

    public String editRelationTest(int serial, String objectId, String targetId, RelationCategory category, String ext,
                                   ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                String relationId = createRelationTest(serial, objectId, targetId, category, ext, resultStatus, resultCode, detail);
                serviceTestContext.getExtend().put("key", relationId);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                String relationId = (String) serviceTestContext.getExtend().get("key");
                RelationEditOrder order = RelationEditOrder.builder()
                        .partnerId(PARTNER_ID)
                        .relationId(relationId)
                        .objectId(objectId)
                        .targetId(targetId)
                        .category(RelationCategory.getRandomEnum())
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                RelationEditResult result = relationService.edit((RelationEditOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                RelationEditResult result = (RelationEditResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((RelationInfo) serviceTestContext.getSingleResult().getInfo()).getRelationId();
    }

    public String createResourceTest(int serial, String parentId, String title, String name, String code, ResourceCategory category, String module, ResourceMenuType menuType, String path, String component, String icon, String color, YesOrNo visible, Integer sort, String ext,
                                     ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                resourceMapper.deleteByName(name);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                ResourceCreateOrder order = ResourceCreateOrder.builder()
                        .partnerId(PARTNER_ID)
                        .parentId(parentId)
                        .title(title)
                        .name(name)
                        .code(code)
                        .category(ResourceCategory.getRandomEnum())
                        .module(module)
                        .menuType(ResourceMenuType.getRandomEnum())
                        .path(path)
                        .component(component)
                        .icon(icon)
                        .color(color)
                        .visible(YesOrNo.getRandomEnum())
                        .sort(null)
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                ResourceCreateResult result = resourceService.create((ResourceCreateOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                ResourceCreateResult result = (ResourceCreateResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((ResourceInfo) serviceTestContext.getSingleResult().getInfo()).getResourceId();
    }

    public String editResourceTest(int serial, String parentId, String title, String name, String code, ResourceCategory category, String module, ResourceMenuType menuType, String path, String component, String icon, String color, YesOrNo visible, Integer sort, String ext,
                                   ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                String resourceId = createResourceTest(serial, parentId, title, name, code, category, module, menuType, path, component, icon, color, visible, sort, ext, resultStatus, resultCode, detail);
                serviceTestContext.getExtend().put("key", resourceId);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                String resourceId = (String) serviceTestContext.getExtend().get("key");
                ResourceEditOrder order = ResourceEditOrder.builder()
                        .partnerId(PARTNER_ID)
                        .resourceId(resourceId)
                        .parentId(parentId)
                        .title(title)
                        .name(name)
                        .code(code)
                        .category(ResourceCategory.getRandomEnum())
                        .module(module)
                        .menuType(ResourceMenuType.getRandomEnum())
                        .path(path)
                        .component(component)
                        .icon(icon)
                        .color(color)
                        .visible(YesOrNo.getRandomEnum())
                        .sort(sort)
                        .ext(ext)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                ResourceEditResult result = resourceService.edit((ResourceEditOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                ResourceEditResult result = (ResourceEditResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((ResourceInfo) serviceTestContext.getSingleResult().getInfo()).getResourceId();
    }

    public String createUserTest(int serial, String loginName, String password, String confirmPassword, String memo,
                                 ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                userMapper.deleteByLoginName(loginName);
                String organizationId = createDefaultOrganizationTest();
                String resourceId     = createDefaultResourceTest();
                String positionId     = createDefaultPositionTest();
                String roleId         = createDefaultRoleTest();
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                UserCreateOrder order = UserCreateOrder.builder()
                        .partnerId(PARTNER_ID)
                        .loginName(loginName)
                        .password(password)
                        .confirmPassword(confirmPassword)
                        .memo(memo)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                UserCreateResult result = userService.create((UserCreateOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                UserCreateResult result = (UserCreateResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((UserInfo) serviceTestContext.getSingleResult().getInfo()).getUserId();
    }

    public String editUserTest(int serial, String loginName, String password, String confirmPassword, String oldPassword, String newPassword, String confirmNewPassword, UserStatus status, String roleIds, String positionIds, String organizationIds, String memo,
                               ResultStatus resultStatus, ResultCode resultCode, String detail) {
        ServiceTestContext serviceTestContext = ServiceTestContext.builder().resultStatus(resultStatus)
                .resultCode(resultCode).build();

        new ServiceTestMockContextThreadLocal(ServiceTestMockContext.builder().expectResultStatus(resultStatus)
                .expectResultCode(resultCode).expectErrorCode(detail).build());
        executeTest(serviceTestContext, new ServiceTestInvoke() {
            @Override
            public void cleanData() {
                String userId = createUserTest(serial, loginName, password, confirmPassword, memo, resultStatus, resultCode, detail);
                serviceTestContext.getExtend().put("key", userId);
            }

            @Override
            public void initData(ServiceTestContext serviceTestContext) {
                String userId = (String) serviceTestContext.getExtend().get("key");
                UserEditOrder order = UserEditOrder.builder()
                        .partnerId(PARTNER_ID)
                        .userId(userId)
                        .oldPassword(oldPassword)
                        .newPassword(newPassword)
                        .confirmNewPassword(confirmNewPassword)
                        .status(UserStatus.getRandomEnum())
                        .roleIds(roleIds)
                        .positionIds(positionIds)
                        .organizationIds(organizationIds)
                        .memo(memo)
                        .build();
                serviceTestContext.setOrder(order);
            }

            @Override
            public void callService(ServiceTestContext serviceTestContext) {
                UserEditResult result = userService.edit((UserEditOrder) serviceTestContext.getOrder());
                serviceTestContext.setSingleResult(result);
            }

            @Override
            public void dataAssert(ServiceTestContext serviceTestContext) {
                UserEditResult result = (UserEditResult) serviceTestContext.getSingleResult();
                Assertions.assertTrue(result.success());
                Assertions.assertNotNull(result.getInfo());
                Assertions.assertTrue(ObjUtil.isNotEmpty(result.getInfo()));
            }
        });
        return ((UserInfo) serviceTestContext.getSingleResult().getInfo()).getUserId();
    }

    protected String createDefaultResourceTest() {
        ResourceEntity entity = ResourceEntity.builder()
                .resourceId(DEFAULT_ID)
                .parentId(DEFAULT_ID)
                .title("默认菜单")
                .name("默认菜单")
                .code("default")
                .category(ResourceCategory.MENU)
                .module("A")
                .menuType(ResourceMenuType.MENU)
                .path("A")
                .component("A")
                .icon("A")
                .color("A")
                .visible(YesOrNo.getRandomEnum())
                .sort(12345)
                .build();
        entity.setPartnerId(PARTNER_ID);
        resourceMapper.deleteByResourceId(DEFAULT_ID);
        resourceMapper.insert(entity);
        return DEFAULT_ID;
    }

    protected String createDefaultRoleTest() {
        RoleEntity entity = RoleEntity.builder()
                .roleId(DEFAULT_ID)
                .organizationId(DEFAULT_ID)
                .name("默认角色")
                .code("default")
                .category(RoleCategory.getRandomEnum())
                .build();
        entity.setPartnerId(PARTNER_ID);
        roleMapper.deleteByRoleId(DEFAULT_ID);
        roleMapper.insert(entity);
        return DEFAULT_ID;
    }

    protected String createDefaultOrganizationTest() {
        OrganizationEntity entity = OrganizationEntity.builder()
                .organizationId(DEFAULT_ID)
                .parentId(DEFAULT_ID)
                .manageId(DEFAULT_ID)
                .name("默认组织")
                .code("default")
                .category(ManageOrgCategory.getRandomEnum())
                .build();
        entity.setPartnerId(PARTNER_ID);
        organizationMapper.deleteByOrganizationId(DEFAULT_ID);
        organizationMapper.insert(entity);
        return DEFAULT_ID;
    }

    protected String createDefaultPositionTest() {
        PositionEntity entity = PositionEntity.builder()
                .positionId(DEFAULT_ID)
                .organizationId(DEFAULT_ID)
                .name("默认职位")
                .code("default")
                .category(PositionCategory.getRandomEnum())
                .build();
        entity.setPartnerId(PARTNER_ID);
        positionMapper.deleteByPositionId(DEFAULT_ID);
        positionMapper.insert(entity);
        return DEFAULT_ID;
    }

}